﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hongapo_Common;

public partial class sysadmin_Product_commentlist : PageBase
{
    private Hongapo_Services.Product.Comment bll = new Hongapo_Services.Product.Comment();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindRepetear();
            ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
        }
        
    }

    public int ID
    {
        get {
            if (!string.IsNullOrEmpty(Request["ID"]))
            {
                return TypeConvert.ToInt32(Request["ID"]);
            }
            return 0;
        }
    }

    private void BindRepetear()
    {
      
        int pageIndex = TypeConvert.ToInt32(Request["page"], 1);
        string whereStr = "1=1";
        if (ID!=0)
        {
            this.btnReturn.Visible = true;
            whereStr = " PID="+ID+"";
        }
        DataSet ds = bll.GetList(this.Pager.PageSize,pageIndex, whereStr, " CreateDate desc");
        if (ds.Tables[1]!=null && ds.Tables[1].Rows.Count>0)
        {
            this.Pager.RecordCount = TypeConvert.ToInt32(ds.Tables[1].Rows[0][0]);
        }
        this.rptList.DataSource = ds.Tables[0];
        this.rptList.DataBind();
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect(ViewState["UrlReferrer"] as string);
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.Equals("del"))
        {
            int id = TypeConvert.ToInt32(e.CommandArgument);
            bll.Delete(id);
            BindRepetear();
        }
    }

    protected void btn_Click(object sender, EventArgs e)
    {
        string IDlist = this.hiddenIDList.Value.Trim(',');
        bll.DeleteList(IDlist);
        BindRepetear();
    }

    /// <summary>
    /// 启用或者停用
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void linkButton_click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int id = TypeConvert.ToInt32(btn.CommandName);
        int isopen = btn.Text == "发布" ? 1 : 0;
        bll.UpdateIsopen(id, isopen);
        BindRepetear();
    }
}
